package com.mateng.treasurechest.view.common

import android.os.Bundle
import android.support.v7.widget.GridLayoutManager
import com.mateng.treasurechest.MAIN_GRID_ROWS_COUNT
import com.mateng.treasurechest.R
import com.mateng.treasurechest.base.BaseActivity
import com.mateng.treasurechest.presenter.BasePresenter
import com.mateng.treasurechest.view.common.adapter.MainGridAdapter
import com.mateng.treasurechest.view.common.bean.MainGridEntity
import com.mateng.treasurechest.view.recipe.activity.RecipeCategoryActivity
import com.mateng.treasurechest.view.weather.activity.WeatherActivity
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : BaseActivity<BasePresenter>() {

    private val arrays = ArrayList<MainGridEntity>()

    private val adapter = MainGridAdapter(arrays)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_main)

        initView()
        initFunctionalAreaData()

    }


    private fun initView() {
        val layoutManager = GridLayoutManager(this, MAIN_GRID_ROWS_COUNT)
        rv_grid_list.layoutManager = layoutManager
        rv_grid_list.adapter = adapter
    }

    private fun initFunctionalAreaData() {
        //添加一个菜谱功能
        val recipe = MainGridEntity()
        recipe.icon = resources.getDrawable(R.mipmap.cover_recipe)
        recipe.title = "菜谱大全"
        recipe.className = RecipeCategoryActivity::class.java
        arrays.add(recipe)

        val weather = MainGridEntity()
        weather.icon = resources.getDrawable(R.mipmap.icon_weather)
        weather.title = "天气预报"
        weather.className = WeatherActivity::class.java
        arrays.add(weather)

        adapter.notifyDataSetChanged()
    }

}
